package com.wengcheng.pay;

import com.wengcheng.pay.zookeeper.MasterSelector;
import com.wengcheng.pay.zookeeper.PayCenter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.I0Itec.zkclient.ZkClient;
import org.I0Itec.zkclient.serialize.SerializableSerializer;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by adengdeng on 2017/8/22
 */
public class PayProvider {

    private final static String CONNECTSTRING = "192.168.124.87:2181,192.168.124.88:2181,192.168.124.89:2181";

    public static void main(String[] args) throws IOException {

        List<MasterSelector> selectorLists = new ArrayList<MasterSelector>();

        for (int i = 0; i < 4; i++) {

            int num = i;

            new Thread(new Runnable() {

                @Override
                public void run() {
                    ZkClient zkClient = new ZkClient(CONNECTSTRING, 5000,
                            5000,
                            new SerializableSerializer());
                    PayCenter payCenter = new PayCenter();

                    payCenter.setId(num);
                    payCenter.setName("payCenter：" + num);

                    MasterSelector selector = new MasterSelector(payCenter, zkClient);
                    selectorLists.add(selector);
                    try {
                        selector.start();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
        System.in.read();
    }
}